<template>
	<om-formsub-outer :index="index" >
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				initValue:{},
				autoformdata: [],
				cachename:'',
				index:null,
				datas:[],
				order:0,
				formdata:{},
				dataCacheKey:"hr-u-entry-data-info-title31-data-cache"
			})
		},
		methods: {
			initLoad(){
				let _that = this
				this.om.request(urlUtil.sysdictComboboxUrl().url,{code:'38392'}).then(res=>{
					//if(res instanceof Array){
					if(Object.prototype.toString.call(res)==='[object Array]'){
						_that.$refs.autoform.changeEditor("title31", "dataId", {
							data:configSelectData(res,"id","dicname")
						})
						_that.$refs.autoform.initSelectIndex("title31", "dataId")
					}else{
						_that.om.toast(res.msg)
					}
				})
			}
		},
		onLoad(e){
			let _that = this
			subOnLoad(_that, e, function() {
				if(e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if(res.data && res.data instanceof Array){
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								//文件深拷贝，否则用户在修改表单删除图片时，引用对象的图片地址也会删除，这里要阻止删除
								var files = _that._.cloneDeep(_that.formdata.files)
								delete _that.formdata.files
								Object.assign(_that.initValue, _that.formdata)
								_that.initValue.files = files
								
								_that.autoformdata[0].order = _that.order
							
								changeEditor(_that.autoformdata[0].editors, "fileList", "fileUploadKey", "121")
								if(_that.formdata.fileList) {
									var tempFileList = []
									var fileUrlList = _that.formdata.fileList.map(t=>{
										tempFileList.push(t.fileSaveName)
										return t.fileSaveName
									})
									changeEditor(_that.autoformdata[0].editors, "fileList", "fileUrlList", fileUrlList)
									changeEditor(_that.autoformdata[0].editors, "fileList", "tempFileList", tempFileList)
								}
								_that.initLoad()
							}
						}
					});
				}
			})
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key: this.dataCacheKey,
					success: function(res) {
						if(res.data) {
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.dataId = d.id
							formdata.dataName = d.dicname
							uni.removeStorage({
								key: _that.dataCacheKey
							});
						}
					}
				});
			}
		}
	}
</script>

<style>

</style>
